package edu.gyc.lover.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.gyc.lover.dao.LoverDao;
import edu.gyc.lover.model.Lover;
import edu.gyc.lover.service.LoverService;
import edu.gyc.lover.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller

@Slf4j
public class GirlController {

    @Resource
    private LoverDao loverDao;
    @Resource
    private LoverService loverService;

    @GetMapping("toupload")
    public Object getHighLovers(Integer n) {
        return "upload";
    }

    @GetMapping("all")
    public String all(Model model) {
        List<Lover> data = loverService.list();
        model.addAttribute("list", data);
        return "index";
    }

    @RequestMapping("/")
    public String lover(Model model, @RequestParam(value = "start",defaultValue = "0") int start, @RequestParam(value = "size",defaultValue = "2") int size) {
        PageHelper.startPage(start, size, "id desc");
        List<Lover> list=loverService.list();
        PageInfo<Lover> pageInfo = new PageInfo<>(list);

        model.addAttribute("imgs", FileUtil.getPicNames());
        model.addAttribute("page",pageInfo);
        return "hi";
    }

    @PostMapping("/addGirl")
    public String add(Lover lover) {
        loverService.saveOrUpdate(lover);
        return "redirect:/";
    }

    @GetMapping("/del")
    public String del(int id){
        log.info("You want del "+id);
        return "/"
        ;
    }
    @GetMapping("/pic")
    public String pic(String pic,Model model){
        
        log.info("You want look "+pic);
        model.addAttribute("pic", pic);
        return "pic";
        
    }
}
